<?php
/**
 * Created by PhpStorm.
 * UserModel: Administrator
 * Date: 2019/3/01/0001
 * Time: 9:59
 */
namespace app\caidongweb\model;

use think\Model;
use think\Db;
class BaseModel extends Model
{
    /*
     * function object_to_array
     * 将对象转成数组
     *
     * @return array
     * */
    function object_to_array($obj) {
        $data = json_decode(json_encode($obj), true);
        return $data;
    }
    /**
     * function returnData
     * 数据返回
     *
     * @return array
     * */
    public function returnData($code,$msg,$data='')
    {
        if($data!=''){
           $state = ['code'=>$code,'msg'=>$msg,'data'=>''];
        }else{
             $state = ['code'=>$code,'msg'=>$msg];
        }
        return $state;
    }

    /**
     * function deletes
     * 批量删除
     *
     * @param string $table 表名
     * @param int $id 数据id
     * @return array
     */
    public function deletes($table,$id)
    {
        $ids = implode(',',$id);
        $res = Db::table($table)->where('ad_id','in',$ids)->delete();
        if($res){
            $status = $this->returnData(1,'删除成功');
        }else{
            $status = $this->returnData(1,'删除失败');
        }
        return $status;
    }
}